60 #include "TObjString.h" 68 #include <unordered_map> 87 void algoEndJob()
override ;
99 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=0,
double HighRange=5400);
279 template <
class T>
bool operator () (
const T& PseudoDetId1,
const T& PseudoDetId2) {
return PseudoDetId1==PseudoDetId2; }
283 std::unordered_map<unsigned int, stAPVGain*>
APVsColl;
315 if( strcmp(
AlgoMode.c_str(),
"WriteOnDB")==0 )
410 if( strcmp(
AlgoMode.c_str(),
"MultiJob")!=0 ){
486 auto const &
Det = tkGeom->
dets();
492 if(!gainHandle.
isValid()){printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
exit(0);}
496 for(
unsigned int i=0;
i<
Det.size();
i++){
504 if(!DetUnit)
continue;
507 unsigned int NAPV = Topo.
nstrips()/128;
509 double Phi = DetUnit->position().basicVector().phi();
510 double Eta = DetUnit->position().basicVector().eta();
511 double R = DetUnit->position().basicVector().transverse();
512 double Thick = DetUnit->surface().bounds().thickness();
514 for(
unsigned int j=0;j<NAPV;j++){
566 if( strcmp(
AlgoMode.c_str(),
"WriteOnDB")==0 || strcmp(
AlgoMode.c_str(),
"Merge")==0){
567 TH1::AddDirectory(kTRUE);
569 TFile*
file =
nullptr;
571 printf(
"Loading New Input File : %s\n",
VInputFiles[
f].c_str());
573 FILE* doesFileExist = fopen(
VInputFiles[
f].c_str(),
"r" );
575 printf(
"File %s doesn't exist\n",
VInputFiles[
f].c_str());
578 fclose(doesFileExist);
581 file =
new TFile(
VInputFiles[
f].c_str() );
if(!file || file->IsZombie() ){printf(
"### Bug With File %s\n### File will be skipped \n",
VInputFiles[
f].c_str());
continue;}
582 APV_Charge ->Add( (TH1*) file->FindObjectAny(
"APV_Charge") , 1);
583 APV_Momentum ->Add( (TH1*) file->FindObjectAny(
"APV_Momentum") , 1);
584 APV_PathLength ->Add( (TH1*) file->FindObjectAny(
"APV_PathLength") , 1);
586 Tracks_P_Vs_Eta ->Add( (TH1*) file->FindObjectAny(
"Tracks_P_Vs_Eta") , 1);
587 Tracks_Pt_Vs_Eta ->Add( (TH1*) file->FindObjectAny(
"Tracks_Pt_Vs_Eta") , 1);
597 HTrackHits ->Add( (TH1*) file->FindObjectAny(
"TrackHits") , 1);
606 Charge_Vs_Alpha ->Add( (TH1*) file->FindObjectAny(
"Charge_Vs_Alpha") , 1);
607 NStrips_Vs_Alpha ->Add( (TH1*) file->FindObjectAny(
"NStrips_Vs_Alpha") , 1);
608 HFirstStrip ->Add( (TH1*) file->FindObjectAny(
"FirstStrip") , 1);
610 TH1F* JobInfo_tmp = (TH1F*) file->FindObjectAny(
"JobInfo");
611 NEvent += (
unsigned int) JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(1));
612 unsigned int tmp_SRun = (
unsigned int) JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(3));
613 unsigned int tmp_SEvent = (
unsigned int) JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(4));
614 unsigned int tmp_ERun = (
unsigned int) JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(6));
615 unsigned int tmp_EEvent = (
unsigned int) JobInfo_tmp->GetBinContent(JobInfo_tmp->GetXaxis()->FindBin(7));
625 printf(
"Deleting Current Input File\n");
638 if( strcmp(
AlgoMode.c_str(),
"MultiJob")!=0 ){
639 TH1D* Proj =
nullptr;
640 double* FitResults =
new double[5];
643 if( I%3650==0 ) printf(
"Fitting Histograms \t %6.2f%%\n",(100.0*I)/
APVsColl.size());
648 Proj =
APV_Charge->ProjectionY(
" ",bin,bin,
"e");
649 Proj = (TH1D*)Proj->Clone();
650 if(Proj==
nullptr)
continue;
654 int SecondAPVId = APV->
APVId;
655 if(SecondAPVId%2==0){
656 SecondAPVId = SecondAPVId+1;
658 SecondAPVId = SecondAPVId-1;
663 TH1D* Proj2 =
APV_Charge->ProjectionY(
" ",bin2,bin2,
"e");
676 TH1D* Proj2 =
APV_Charge->ProjectionY(
" ",bin2,bin2,
"e");
689 APV->
MPV = FitResults[0];
691 if(FitResults[0]!=-0.5 && FitResults[1]<
MaxMPVError){
742 if(FitResults[0]!=-0.5){
754 if(Proj==
nullptr)
continue;
761 unsigned int GOOD = 0;
762 unsigned int BAD = 0;
763 double MPVmean =
MPVs->GetMean();
769 APV->
Gain = APV->
MPV / MPVmean;
939 fprintf(Gains,
"NEvents = %i\n",
NEvent);
940 fprintf(Gains,
"Number of APVs = %lu\n",static_cast<unsigned long>(
APVsColl.size()));
941 fprintf(Gains,
"GoodFits = %i BadFits = %i ratio = %f\n",GOOD,BAD,(100.0*GOOD)/(GOOD+BAD));
947 std::vector<int> DetIdOfBuggedAPV;
948 fprintf(Gains,
"----------------------------------------------------------------------\n");
951 if(APV->
MPV>0 && APV->
MPV<200){
953 for(
unsigned int b=0;
b<DetIdOfBuggedAPV.size()&&!tmpBug;
b++){
if(DetIdOfBuggedAPV[
b]==APV->
DetId)tmpBug=
true;}
954 if(!tmpBug){fprintf(Gains,
"%i,\n",APV->
DetId);DetIdOfBuggedAPV.push_back(APV->
DetId);}
976 if(!gainHandle.
isValid()){printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
exit(0);}
989 printf(
"GAIN HANDLE IS NOT VALID\n");
1003 if( strcmp(
AlgoMode.c_str(),
"WriteOnDB")==0 )
return;
1036 for(Trajectory::RecHitContainer::const_iterator rechit = transRecHits.begin(); rechit != transRecHits.end(); ++rechit)
1037 if ((*rechit)->isValid()) ndof += (*rechit)->dimension();
1044 vector<TrajectoryMeasurement> measurements = traj.
measurements();
1067 for(vector<TrajectoryMeasurement>::const_iterator measurement_it = measurements.begin(); measurement_it!=measurements.end(); measurement_it++){
1070 if( !trajState.
isValid() )
continue;
1077 if(sistripsimplehit){
1079 }
else if(sistripmatchedhit){
1082 }
else if(sistripsimple1dhit){
1096 double cosine = trackDirection.
z()/trackDirection.
mag();
1100 int APVId = FirstStrip/128;
1103 bool Overlaping =
false;
1105 unsigned int NHighStrip = 0;
1110 if(FirstStrip==0 )Overlaping=
true;
1111 if(FirstStrip==128 )Overlaping=
true;
1112 if(FirstStrip==256 )Overlaping=
true;
1113 if(FirstStrip==384 )Overlaping=
true;
1114 if(FirstStrip==512 )Overlaping=
true;
1115 if(FirstStrip==640 )Overlaping=
true;
1117 if(FirstStrip<=127 && FirstStrip+Ampls.size()>127)Overlaping=
true;
1118 if(FirstStrip<=255 && FirstStrip+Ampls.size()>255)Overlaping=
true;
1119 if(FirstStrip<=383 && FirstStrip+Ampls.size()>383)Overlaping=
true;
1120 if(FirstStrip<=511 && FirstStrip+Ampls.size()>511)Overlaping=
true;
1121 if(FirstStrip<=639 && FirstStrip+Ampls.size()>639)Overlaping=
true;
1123 if(FirstStrip+Ampls.size()==127 )Overlaping=
true;
1124 if(FirstStrip+Ampls.size()==255 )Overlaping=
true;
1125 if(FirstStrip+Ampls.size()==383 )Overlaping=
true;
1126 if(FirstStrip+Ampls.size()==511 )Overlaping=
true;
1127 if(FirstStrip+Ampls.size()==639 )Overlaping=
true;
1128 if(FirstStrip+Ampls.size()==767 )Overlaping=
true;
1129 if(Overlaping)
return -1;
1141 for(
unsigned int a=0;
a<Ampls.size();
a++){Charge+=Ampls[
a];
if(Ampls[
a]>=254)Saturation++;
if(Ampls[
a]>=20)NHighStrip++;}
1143 double ClusterChargeOverPath = (double)Charge / path ;
1159 double trans = atan2(trackDirection.
y(),trackDirection.
x())*(180/3.14159265);
1160 double alpha = acos(trackDirection.
x() /
sqrt(
pow(trackDirection.
x(),2) +
pow(trackDirection.
z(),2) ) ) * (180/3.14159265);
1161 double beta = acos(trackDirection.
y() /
sqrt(
pow(trackDirection.
x(),2) +
pow(trackDirection.
z(),2) ) ) * (180/3.14159265);
1163 if(path>0.4 && path<0.45){
1189 return ClusterChargeOverPath;
1200 if (dynamic_cast<const StripGeomDetUnit*>(it)==
nullptr && dynamic_cast<const PixelGeomDetUnit*>(it)==
nullptr) {
1201 std::cout <<
"this detID doesn't seem to belong to the Tracker" << std::endl;
1206 const TrapezoidalPlaneBounds* trapezoidalBounds( dynamic_cast<const TrapezoidalPlaneBounds*>(&(plane.bounds())));
1207 const RectangularPlaneBounds* rectangularBounds( dynamic_cast<const RectangularPlaneBounds*>(&(plane.bounds())));
1209 double DistFromBorder = 1.0;
1213 if(trapezoidalBounds)
1215 std::array<const float, 4>
const &
parameters = (*trapezoidalBounds).parameters();
1216 HalfLength = parameters[3];
1219 }
else if(rectangularBounds){
1222 }
else{
return false;}
1225 if (fabs(HitLocalPos.
y())+HitLocalError.
yy() >= (HalfLength - DistFromBorder) )
return false;
1233 double adcs_err = 0.;
1234 double width = -0.5;
1235 double width_err = 0;
1236 double chi2overndf = -0.5;
1238 double nr_of_entries = InputHisto->GetEntries();
1241 FitResults[0] = adcs;
1242 FitResults[1] = adcs_err;
1243 FitResults[2] =
width;
1244 FitResults[3] = width_err;
1245 FitResults[4] = chi2overndf;
1250 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
1251 MyLandau->SetParameter(
"MPV",300);
1253 InputHisto->Fit(MyLandau,
"QR WW");
1256 adcs = MyLandau->GetParameter(
"MPV");
1257 adcs_err = MyLandau->GetParError(1);
1258 width = MyLandau->GetParameter(2);
1259 width_err = MyLandau->GetParError(2);
1260 chi2overndf = MyLandau->GetChisquare() / MyLandau->GetNDF();
1264 adcs = -0.5; adcs_err = 0.;
1265 width = -0.5; width_err = 0;
1269 FitResults[0] = adcs;
1270 FitResults[1] = adcs_err;
1271 FitResults[2] =
width;
1272 FitResults[3] = width_err;
1273 FitResults[4] = chi2overndf;
1283 cout <<
"START getNewObject\n";
1290 std::vector<float>* theSiStripVector =
nullptr;
1291 int PreviousDetId = -1;
1295 if(APV==
nullptr){ printf(
"Bug\n");
continue; }
1296 if(APV->
DetId != PreviousDetId){
1297 if(theSiStripVector!=
nullptr){
1299 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1302 theSiStripVector =
new std::vector<float>;
1303 PreviousDetId = APV->
DetId;
1306 theSiStripVector->push_back(APV->
Gain);
1310 if(theSiStripVector!=
nullptr){
1312 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1315 cout <<
"END getNewObject\n";
ClusterRef cluster() const
double p() const
momentum vector magnitude
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
virtual float length() const =0
void algoEndJob() override
SiStripGainFromData(const edm::ParameterSet &)
TH2F * HitLocalPositionBefCut
friend struct const_iterator
const_iterator end() const
last iterator over the map (read only)
unsigned int MinNrEntries
std::vector< stAPVGain * > APVsCollOrdered
#define DEFINE_FWK_MODULE(type)
SiStripCluster const & monoCluster() const
LocalVector localDirection() const
LocalPoint localPosition() const
TH1F * NSatStripInCluster
bool IsFarFromBorder(TrajectoryStateOnSurface trajState, const uint32_t detid, const edm::EventSetup *iSetup)
constexpr uint32_t rawId() const
get the raw id
void algoBeginRun(const edm::Run &, const edm::EventSetup &) override
ConstRecHitContainer recHits() const
const Bounds & bounds() const
uint16_t firstStrip() const
TH1F * FWHM_Vs_PathLength320
const Plane & surface() const
The nominal surface of the GeomDet.
const edm::EventSetup * iSetup_
LocalError positionError() const
TH2F * NStrips_Vs_TransversAngle
TH2F * Charge_Vs_PathTEC1
TH1F * FWHM_Vs_PathLength500
bool put(const uint32_t &detID, Range input)
TH1F * MPV_Vs_TransversAngle
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
DataContainer const & measurements() const
vector< string > VInputFiles
~SiStripGainFromData() override
double eta() const
pseudorapidity of momentum vector
TH1F * FWHM_Vs_PathLength
std::unordered_map< unsigned int, stAPVGain * > APVsColl
double pt() const
track transverse momentum
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
TH1F * MPV_Vs_PathLength320
ClusterRef cluster() const
TH2F * Charge_Vs_PathTEC2
const LocalTrajectoryError & localError() const
double MaxTrackChiOverNdf
void algoBeginJob(const edm::EventSetup &) override
TH1F * NumberOfEntriesByAPV
unsigned long long TimeValue_t
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
TH2F * Charge_Vs_PathLength500
unsigned int MinTrackHits
bin
set the eta bin as selection string.
ConstRecHitContainer RecHitContainer
TH2F * Charge_Vs_PathLength
T const * product() const
double ComputeChargeOverPath(const SiStripCluster *Cluster, TrajectoryStateOnSurface trajState, const edm::EventSetup *iSetup, const Track *track, double trajChi2OverN)
void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
TH2F * Charge_Vs_TransversAngle
virtual int nstrips() const =0
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=0, double HighRange=5400)
std::string TrajToTrackLabel
SiStripCluster const & stereoCluster() const
TH2F * Charge_Vs_PathLength320
GlobalVector globalMomentum() const
TH1F * NHighStripInCluster
const_iterator begin() const
first iterator over the map (read only)
std::string TrajToTrackProducer
T const * product() const
SiStripApvGain * getNewObject() override
TimeValue_t value() const
const std::vector< uint8_t > & amplitudes() const
edm::Timestamp time() const
Power< A, B >::type pow(const A &a, const B &b)
const edm::Event * iEvent_
DQMStore * dqmStore_infile
unsigned int tecSide(const DetId &id) const
TH1F * MPV_Vs_PathLength500
const SiStripApvGain::Range getRange(uint32_t detID) const