63 #include "TObjString.h"
73 #include <ext/hash_map>
80 using namespace __gnu_cxx;
81 using __gnu_cxx::hash_map;
119 virtual void algoEndJob ()
override;
122 void algoAnalyzeTheTree();
123 void algoComputeMPVandGain();
125 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=50,
double HighRange=5400);
126 bool IsGoodLandauFit(
double* FitResults);
129 void MakeCalibrationMap();
179 template <
class T>
bool operator () (
const T& PseudoDetId1,
const T& PseudoDetId2) {
return PseudoDetId1==PseudoDetId2; }
183 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >
APVsColl;
234 vector<GeomDet*>
Det = tkGeom->dets();
238 if(!gainHandle.
isValid()){printf(
"\n#####################\n\nERROR --> gainHandle is not valid\n\n#####################\n\n");
exit(0);}
241 for(
unsigned int i=0;
i<gainHandle->getNumberOfTags();
i++){
242 printf(
"Reccord %i --> Rcd Name = %s Label Name = %s\n",
i,gainHandle->getRcdName(
i).c_str(), gainHandle->getLabelName(
i).c_str());
250 unsigned int Index=0;
251 for(
unsigned int i=0;
i<Det.size();
i++){
252 DetId Detid = Det[
i]->geographicalId();
259 if(!DetUnit)
continue;
262 unsigned int NAPV = Topo.
nstrips()/128;
263 for(
unsigned int j=0;
j<NAPV;
j++){
288 if(gainHandle->getNumberOfTags()!=2){printf(
"ERROR: NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n");fflush(stdout);
exit(0);};
328 FitResults[0] = -0.5;
330 FitResults[2] = -0.5;
332 FitResults[4] = -0.5;
337 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
338 MyLandau->SetParameter(1,300);
339 InputHisto->Fit(
"MyLandau",
"0QR WW");
342 FitResults[0] = MyLandau->GetParameter(1);
343 FitResults[1] = MyLandau->GetParError(1);
344 FitResults[2] = MyLandau->GetParameter(2);
345 FitResults[3] = MyLandau->GetParError(2);
346 FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF();
352 if(FitResults[0] < 2 )
return false;
362 printf(
"Openning file %3i/%3i --> %s\n",
i+1, (
int)
VInputFiles.size(), (
char*)(
VInputFiles[
i].c_str())); fflush(stdout);
363 TChain*
tree =
new TChain(
"gainCalibrationTree/tree");
366 TString EventPrefix(
"");
367 TString EventSuffix(
"");
369 TString TrackPrefix(
"track");
370 TString TrackSuffix(
"");
372 TString CalibPrefix(
"GainCalibration");
373 TString CalibSuffix(
"");
375 unsigned int eventnumber = 0; tree->SetBranchAddress(EventPrefix +
"event" + EventSuffix, &eventnumber ,
NULL);
376 unsigned int runnumber = 0; tree->SetBranchAddress(EventPrefix +
"run" + EventSuffix, &runnumber ,
NULL);
377 std::vector<bool>* TrigTech = 0; tree->SetBranchAddress(EventPrefix +
"TrigTech" + EventSuffix, &TrigTech ,
NULL);
379 std::vector<double>* trackchi2ndof = 0; tree->SetBranchAddress(TrackPrefix +
"chi2ndof" + TrackSuffix, &trackchi2ndof ,
NULL);
380 std::vector<float>* trackp = 0; tree->SetBranchAddress(TrackPrefix +
"momentum" + TrackSuffix, &trackp ,
NULL);
381 std::vector<float>* trackpt = 0; tree->SetBranchAddress(TrackPrefix +
"pt" + TrackSuffix, &trackpt ,
NULL);
382 std::vector<double>* tracketa = 0; tree->SetBranchAddress(TrackPrefix +
"eta" + TrackSuffix, &tracketa ,
NULL);
383 std::vector<double>* trackphi = 0; tree->SetBranchAddress(TrackPrefix +
"phi" + TrackSuffix, &trackphi ,
NULL);
384 std::vector<unsigned int>* trackhitsvalid = 0; tree->SetBranchAddress(TrackPrefix +
"hitsvalid" + TrackSuffix, &trackhitsvalid,
NULL);
386 std::vector<int>* trackindex = 0; tree->SetBranchAddress(CalibPrefix +
"trackindex" + CalibSuffix, &trackindex ,
NULL);
387 std::vector<unsigned int>* rawid = 0; tree->SetBranchAddress(CalibPrefix +
"rawid" + CalibSuffix, &rawid ,
NULL);
388 std::vector<float>* localdirx = 0; tree->SetBranchAddress(CalibPrefix +
"localdirx" + CalibSuffix, &localdirx ,
NULL);
389 std::vector<float>* localdiry = 0; tree->SetBranchAddress(CalibPrefix +
"localdiry" + CalibSuffix, &localdiry ,
NULL);
390 std::vector<float>* localdirz = 0; tree->SetBranchAddress(CalibPrefix +
"localdirz" + CalibSuffix, &localdirz ,
NULL);
391 std::vector<unsigned short>* firststrip = 0; tree->SetBranchAddress(CalibPrefix +
"firststrip" + CalibSuffix, &firststrip ,
NULL);
392 std::vector<unsigned short>* nstrips = 0; tree->SetBranchAddress(CalibPrefix +
"nstrips" + CalibSuffix, &nstrips ,
NULL);
393 std::vector<bool>* saturation = 0; tree->SetBranchAddress(CalibPrefix +
"saturation" + CalibSuffix, &saturation ,
NULL);
394 std::vector<bool>* overlapping = 0; tree->SetBranchAddress(CalibPrefix +
"overlapping" + CalibSuffix, &overlapping ,
NULL);
395 std::vector<bool>* farfromedge = 0; tree->SetBranchAddress(CalibPrefix +
"farfromedge" + CalibSuffix, &farfromedge ,
NULL);
396 std::vector<unsigned int>*
charge = 0; tree->SetBranchAddress(CalibPrefix +
"charge" + CalibSuffix, &charge ,
NULL);
397 std::vector<float>*
path = 0; tree->SetBranchAddress(CalibPrefix +
"path" + CalibSuffix, &path ,
NULL);
398 std::vector<float>* chargeoverpath = 0; tree->SetBranchAddress(CalibPrefix +
"chargeoverpath" + CalibSuffix, &chargeoverpath,
NULL);
399 std::vector<unsigned char>* amplitude = 0; tree->SetBranchAddress(CalibPrefix +
"amplitude" + CalibSuffix, &litude ,
NULL);
400 std::vector<double>* gainused = 0; tree->SetBranchAddress(CalibPrefix +
"gainused" + CalibSuffix, &gainused ,
NULL);
403 printf(
"Number of Events = %i + %i = %i\n",
NEvent,(
unsigned int)tree->GetEntries(),(
unsigned int)(
NEvent+tree->GetEntries()));
404 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
405 printf(
"Looping on the Tree :");
406 int TreeStep = tree->GetEntries()/50;
if(TreeStep<=1)TreeStep=1;
407 for (
unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
409 if(ientry%TreeStep==0){printf(
".");fflush(stdout);}
410 tree->GetEntry(ientry);
418 unsigned int FirstAmplitude=0;
419 for(
unsigned int i=0;
i<(*chargeoverpath).size();
i++){
420 FirstAmplitude+=(*nstrips)[
i];
421 int TI = (*trackindex)[
i];
428 if((*farfromedge)[
i] ==
false )
continue;
429 if((*overlapping)[
i] ==
true )
continue;
452 bool Saturation =
false;
453 for(
unsigned int s=0;
s<(*nstrips)[
i];
s++){
454 int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[
i]+
s];
458 if(StripCharge>1024){
461 }
else if(StripCharge>254){
465 Charge += StripCharge;
469 Charge = (*charge)[
i];
474 double ClusterChargeOverPath = ( (double) Charge )/(*path)[
i] ;
475 if(
Validation) {ClusterChargeOverPath/=(*gainused)[
i];}
492 }
else if(APV->
Eta>0){
510 double FitResults[5];
511 double MPVmean = 300;
513 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
514 printf(
"Fitting Charge Distribution :");
517 if(I%TreeStep==0){printf(
".");fflush(stdout);}
526 int SecondAPVId = APV->
APVId;
527 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
530 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
532 for(
unsigned int i=0;
i<6;
i++){
533 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >::iterator tmpit;
540 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
548 APV->
FitMPV = FitResults[0];
576 unsigned int tree_Index;
577 unsigned int tree_Bin;
578 unsigned int tree_DetId;
579 unsigned char tree_APVId;
580 unsigned char tree_SubDet;
587 float tree_Thickness;
589 float tree_FitMPVErr;
591 float tree_FitWidthErr;
592 float tree_FitChi2NDF;
594 double tree_PrevGain;
595 double tree_NEntries;
599 MyTree =
tfs->
make<TTree> (
"APVGain",
"APVGain");
600 MyTree->Branch(
"Index" ,&tree_Index ,
"Index/i");
601 MyTree->Branch(
"Bin" ,&tree_Bin ,
"Bin/i");
602 MyTree->Branch(
"DetId" ,&tree_DetId ,
"DetId/i");
603 MyTree->Branch(
"APVId" ,&tree_APVId ,
"APVId/b");
604 MyTree->Branch(
"SubDet" ,&tree_SubDet ,
"SubDet/b");
605 MyTree->Branch(
"x" ,&tree_x ,
"x/F");
606 MyTree->Branch(
"y" ,&tree_y ,
"y/F");
607 MyTree->Branch(
"z" ,&tree_z ,
"z/F");
608 MyTree->Branch(
"Eta" ,&tree_Eta ,
"Eta/F");
609 MyTree->Branch(
"R" ,&tree_R ,
"R/F");
610 MyTree->Branch(
"Phi" ,&tree_Phi ,
"Phi/F");
611 MyTree->Branch(
"Thickness" ,&tree_Thickness ,
"Thickness/F");
612 MyTree->Branch(
"FitMPV" ,&tree_FitMPV ,
"FitMPV/F");
613 MyTree->Branch(
"FitMPVErr" ,&tree_FitMPVErr ,
"FitMPVErr/F");
614 MyTree->Branch(
"FitWidth" ,&tree_FitWidth ,
"FitWidth/F");
615 MyTree->Branch(
"FitWidthErr" ,&tree_FitWidthErr,
"FitWidthErr/F");
616 MyTree->Branch(
"FitChi2NDF" ,&tree_FitChi2NDF ,
"FitChi2NDF/F");
617 MyTree->Branch(
"Gain" ,&tree_Gain ,
"Gain/D");
618 MyTree->Branch(
"PrevGain" ,&tree_PrevGain ,
"PrevGain/D");
619 MyTree->Branch(
"NEntries" ,&tree_NEntries ,
"NEntries/D");
620 MyTree->Branch(
"isMasked" ,&tree_isMasked ,
"isMasked/O");
624 fprintf(Gains,
"NEvents = %i\n",
NEvent);
625 fprintf(Gains,
"NTracks = %i\n",
NTrack);
626 fprintf(Gains,
"NClusters = %i\n",
NCluster);
627 fprintf(Gains,
"Number of APVs = %lu\n",static_cast<unsigned long>(
APVsColl.size()));
628 fprintf(Gains,
"GoodFits = %i BadFits = %i ratio = %f\n",
GOOD,
BAD,(100.0*
GOOD)/(
GOOD+
BAD));
632 if(APV==
NULL)
continue;
636 tree_Index = APV->
Index;
638 tree_DetId = APV->
DetId;
639 tree_APVId = APV->
APVId;
640 tree_SubDet = APV->
SubDet;
648 tree_FitMPV = APV->
FitMPV;
652 tree_FitChi2NDF = APV->
FitChi2;
653 tree_Gain = APV->
Gain;
670 std::vector<float>* theSiStripVector =
NULL;
671 unsigned int PreviousDetId = 0;
675 if(APV==
NULL){ printf(
"Bug\n");
continue; }
676 if(APV->
DetId != PreviousDetId){
677 if(theSiStripVector!=
NULL){
679 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
681 theSiStripVector =
new std::vector<float>;
682 PreviousDetId = APV->
DetId;
684 theSiStripVector->push_back(APV->
Gain);
686 if(theSiStripVector!=
NULL){
688 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
703 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
706 unsigned int tree_DetId;
707 unsigned char tree_APVId;
710 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
711 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
712 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
714 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
715 t1->GetEntry(ientry);
T getParameter(std::string const &) const
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
unsigned int MinTrackHits
T y() const
Cartesian y coordinate.
edm::Service< TFileService > tfs
T x() const
Cartesian x coordinate.
SiStripApvGain * getNewObject() override
~SiStripGainFromCalibTree()
#define DEFINE_FWK_MODULE(type)
SiStripGainFromCalibTree(const edm::ParameterSet &)
const Bounds & bounds() const
T * make(const Args &...args) const
make new ROOT object
TH2F * Charge_Vs_PathlengthTECP2
Geom::Phi< T > phi() const
virtual const StripTopology & specificTopology() const
Returns a reference to the strip proxy topology.
TH2F * Charge_Vs_PathlengthTECP1
const Plane & surface() const
The nominal surface of the GeomDet.
void MakeCalibrationMap()
double MaxTrackChiOverNdf
bool put(const uint32_t &detID, Range input)
uint32_t rawId() const
get the raw id
virtual float thickness() const =0
TH2F * Charge_Vs_PathlengthTOB
std::vector< stAPVGain * > APVsCollOrdered
__gnu_cxx::hash_map< unsigned int, stAPVGain *, __gnu_cxx::hash< unsigned int >, isEqual > APVsColl
virtual void algoBeginJob(const edm::EventSetup &) override
void algoComputeMPVandGain()
const Surface::PositionType & position() const
The position (origin of the R.F.)
TH2F * Charge_Vs_PathlengthTIB
T z() const
Cartesian z coordinate.
bool IsGoodLandauFit(double *FitResults)
TH2F * Charge_Vs_PathlengthTIDM
TH2F * Charge_Vs_Index_Absolute
std::pair< ContainerIterator, ContainerIterator > Range
const std::complex< double > I
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
TH2F * Charge_Vs_PathlengthTECM2
vector< string > VInputFiles
virtual void algoEndJob() override
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
void algoAnalyzeTheTree()
T transverse() const
Another name for perp()
TH2F * Charge_Vs_PathlengthTECM1
volatile std::atomic< bool > shutdown_flag false
const BasicVectorType & basicVector() const
TH2F * Charge_Vs_PathlengthTIDP